package org.fhawk.tinyspring;

import org.fhawk.tinyspring.aop.AopHelper;
import org.fhawk.tinyspring.exception.JdkVersionNotAccessExcepiton;
import org.fhawk.tinyspring.ioc.BeanHelper;
import org.fhawk.tinyspring.ioc.IocHelper;
import org.fhawk.tinyspring.mvc.ActionHelper;
import org.fhawk.tinyspring.orm.DataBaseHelper;
import org.fhawk.tinyspring.util.ClassUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by tuo on 10/9/16.
 */
public class HelperLoader {
    private static Logger logger = LoggerFactory.getLogger(HelperLoader.class);

    private HelperLoader() {
    }

    public static void init() throws JdkVersionNotAccessExcepiton {
        //判断java版本
        if (ClassUtil.getJDKVersion() < 52) {
            throw new JdkVersionNotAccessExcepiton("必须使用版本为1.8+ 的JDK");
        }
        // 定义需要加载的 Helper 类
        Class<?>[] classList = {
            BeanHelper.class,
            DataBaseHelper.class,
            IocHelper.class,
            AopHelper.class,
            ActionHelper.class
        };
        // 按照顺序加载类
        for (Class<?> cls : classList) {
            logger.debug("加载类:{}", cls.getSimpleName());
            ClassUtil.loadClass(cls.getName());
        }
    }
}
